package com.msb.mallsearch.controller;

import com.msb.common.dao.es.SkuESModel;
import com.msb.common.exception.BizCodeEnume;
import com.msb.common.utils.R;
import com.msb.mallsearch.service.ElasticSearchSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: xixifeng
 * @Date: 2022/10/18 - 10 - 18 - 20:20
 * @Description: com.msb.mallsearch.controller
 * @version: 1.0
 */

@RestController
@RequestMapping("/search/save")
public class ElasticSearchSaveController {


    @Autowired
    private ElasticSearchSaveService service;

    /**
     * 存储商品上架信息到ElasticSearch服务的接口
     * @return
     */
    @PostMapping("/product")
    public R productStatusUp(@RequestBody List<SkuESModel> skuESModels) {

        Boolean b =false;
        try {
            b = service.productStatusUp(skuESModels);
        } catch (Exception e) {
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if (b) {
            return R.ok();
        }

        return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
    }
}
